<template>
    <div class="container">
        <i class="el-icon-close close-top" @click="cancel"></i>
        <el-button type="success" icon="d-arrow-left" @click="cancel" size="small">返回</el-button>
        <!-- 数据表格展示区域 -->
        <el-table
            :data="dataList"
            :v-loading="false"
            element-loading-text="拼命加载中"
            border
            stripe
            align="center"
            class="admin-table"
            :row-class-name="tableRowClassName">


            <el-table-column
                :prop="v.prop"
                :label="v.label"
                v-for="(v,index) in portTitleList"
                align="center"
                show-overflow-tooltip
                v-if="v.hide != 0"
                :formatter="v.formatter"
                :align="v.align || 'center'"
                :fixed="v.fixed"
                :class-name="v.columnStyle"
                :width="v.width"
                :min-width="v.minWidth"
                :header-align="v.headerAlign || 'center'"
                >
                <!-- <template scope="scope">

                     <div slot="reference" :style="tableCellControl(scope)">
                         <span v-if="scope.column.property == 'splx'" v-html="scope.row.splx == 1 ? '课时':'物品'"></span>
                         <span v-else>{{ scope.row[scope.column.property] }}</span>

                     </div>
                  </template>  -->
            </el-table-column>
        </el-table>

        <!-- 分页查询区域 -->
        <!-- <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageindex"
            :page-sizes="pagesizes"
            :page-size="pagesize"
            :layout="layout"
            :total="total"
            class="class-page">
        </el-pagination> -->


        <!-- 各个组件显示区域 -->

        <!-- 动画加载 -->
        <LoadingComponent v-show="isLoading"></LoadingComponent>

        <!-- 子路由显示区域 -->
        <router-view class="port-view"></router-view>
    </div>
</template>

<script>

    import qs from 'qs'
    import { mapState } from 'vuex'
    import LoadingComponent from 'components/loading'
    export default {
        components: { LoadingComponent },
        props: ['params'],
        data () {
            return {

                /*组件区域*/
                portComponents: {
                    singleDelete: {
                        type: 'singleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'single',
                            title: '此操作将删除该班级, 是否继续?'
                        }
                    },
                    multipleDelete: {
                        type: 'multipleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'multiple',
                            title: '此操作将删除您选中的班级, 是否继续?'
                        }
                    },
                    add: {
                        type: 'add',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    edit: {
                        type: 'edit',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    info: {
                        type: 'info',
                        toggle: false,
                        params: '',
                        data: {}
                    }
                },

                multipleDelNum:'', //获取批量选择的数据
                dataList: [],  //表格数据

                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                */
                portTitleList: [
                    {
                        prop:'id',
                        label:'id',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },{
                        prop:'splx',
                        label:'商品类型',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {
                            // console.log(row, column)
                            return row.splx == 1 ? '课时' : '物品'
                        }
                    },{
                        prop:'spmc',
                        label:'商品名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center'
                    },{
                        prop:'jg',
                        label:'价格',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center'
                    },{
                        prop:'cns',
                        label:'数量',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center'
                    },{
                        prop:'dw',
                        label:'单位',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {
                            return row.splx == 1 ? '次数' : row.dw ? row.dw : '套'
                        }
                    },{
                        prop:'yhj',
                        label:'优惠金额（-）',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center'
                    },{
                        prop:'zk',
                        label:'折扣',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {
                            return row.zk + "%"
                        }
                    }
                ],
                portBntList: [//接口按钮列表
                    {
                        name:'编辑',
                        type:'edit'
                    },
                    {
                        name:'详情',
                        type:'info'
                    },
                    {
                        name:'删除',
                        type:'singleDelete'
                    }
                ],

                /*动画加载*/
                isLoading: true,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画

                /*模糊搜索条件*/
                inputjkname:'' , //  接口名称,


                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
                pageindex: 1,//当前分页页码
                pagesizes: [12, 24, 36, 72],//显示个数的选择器选项
                pagesize: 12,//每页显示条目数
                total: 0,//总条数


                dropDownData:'', //
            }
        },
        created () {

            //加载页面时调用
            this.$store.dispatch('changeTitle','物品详情');//修改title
            this.$store.dispatch('changeRouterIndex','/cost/payjl');//修改路由


            this.search();//分页获取默认数据

            this.isLoading = true;//动画开始

        },
        mounted () {
            this.isLoading = false;//动画结束
        },
        methods: {
            tableRowClassName (row, index) {//隔行变色颜色设置
                /*if ( index%4 == 0) {
                    return "table-cell-green";
                }else if( index%4 == 1 ){
                    return "table-cell-yellow";
                }else if( index%4 == 2 ){
                    return "table-cell-red";
                }else{
                    return "table-cell-blue"
                }*/
            },
            tableCellControl (scope) {//表格单元格控制CSS样式
                /*if (scope.row.id == 112 && scope.column.property == "iname") {
                    return {
                        color:"red",
                    }
                }else{
                    return {
                        color:"green",
                    }
                }*/
            },
            cancel () {
               this.$emit('close',{type:'details',cancel:true})
            },

            search () {//查询搜索触发事件
              // alert(this.params.row.orderid)
              var params3 = qs.stringify({
  							orderid: this.params.row.orderid
  						});
                this.axios.post(this.$store.state.api + 'order/listwp',params3)
                .then( res => {
                    console.log(res)

                    let list = res.data.data.list;
                    // this.total = data.totalPage;
                    // console.log(111)
                    var arr = []
                    list.forEach(v => {
                        if (v.splx) {
                            arr.push(v)
                        }
                    })

                    this.dataList = this.dataList.concat(arr);


                    this.searchLoading = false;
                }).catch( res => {
                    console.log(res)
                    this.searchLoading = false;
                })


                var params2 = qs.stringify({
    							orderid: this.params.row.orderid
    						});
                this.axios.post(this.$store.state.api + 'order/listks',params2)
                .then( res => {
                    console.log(res)

                    let list = res.data.data.list;
                    var arr = [];
                    list.forEach(v => {
                        if (v.splx) {
                            arr.push(v)
                        }
                    })
                    this.dataList = this.dataList.concat(arr);

                    this.searchLoading = false;
                }).catch( res => {
                    console.log(res)
                    this.searchLoading = false;
                })


            },


            handleSizeChange (val) {//每页显示条数触发事件
                this.pagesize = val;
                this.pageindex = 1;
                this.search();
            },

            handleCurrentChange (val) {//分页触发事件
                this.search();
            }



        }
    }
</script>
<style lang="less" scoped>
    .admin-table {
        margin-top:35px;
    }
</style>
